home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Trading on the Edge
/
Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin
/
pc
/
mac_file
/
vendor_d
/
neuralwa
/
nw2v50
/
demo_net
/
conv.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-23
|
4KB
|
108 lines
/* 10:15 04-Jul-88 (conv.c) Convert RAW Stock Prices to Scaled Prices */
/************************************************************************
* Copyright(C) 1987-1992 NeuralWare Inc *
* Penn Center West, IV-227, Pittsburgh, PA 15276 *
* Telephone: (412) 787-8222 FAX: (412) 787-8220 *
* *
* All rights reserved. No part of this program may be reproduced, *
* stored in a retrieval system, or transmitted, in any form or by any *
* means, electronic, mechanical, photocopying, recording or otherwise *
* without the prior written permission of the copyright owner, *
* NeuralWare, Inc. *
* *
* PROPRIETARY NOTICE *
* *
* This document is the property of NeuralWare, Inc. and contains *
* trade-secrets and other proprietary information. The information *
* herein is reserved as proprietary to NeuralWare, and is not to be *
* published, reproduced, copied, disclosed, used, or reverse *
* engineered without the express written consent of a duly authorized *
* representative of NeuralWare. *
************************************************************************
*/
/************************************************************************
* *
* Convert RAW stock prices to SCALED stock prices *
* *
************************************************************************
To use this program:
CONV input.file output.file
It will take the input file, one data item per input line, and
re-scale them to the range 0.1 to 0.9. This was used for both
the stock prediction and noise filtering examples. In the case of
noise filtering, only the output files are provided.
If no arguments are given, it assumes "sp500.nnz" as input and
"sp500.in" for output.
*/
#include <stdio.h>
#undef max
#undef min
main( ac, av )
int ac; /* # of input arguments */
char **av; /* array of pointers to the arguments */
{
FILE *ifp; /* input file pointer */
FILE *ofp; /* output file pointer */
float flt; /* work number for sscanf */
double max, min; /* max and min of input */
double scale, offset; /* computed scale and offset */
char *ifn, *ofn; /* input file name and output file name */
if ( ac > 2 ) {
ifn = av[1];
ofn = av[2];
} else {
ifn = "sp500.nnz";
ofn = "sp500.in";
}
ifp = fopen( ifn, "r" ); /* raw input prices */
ofp = fopen( ofn, "w" ); /* scaled output prices */
if ( ifp == (FILE *)0 ) {
fprintf( stderr, "Could not open input file <%s>\n", ifn );
exit( 1 );
}
if ( ofp == (FILE *)0 ) {
fprintf( stderr, "Could not open output file <%s>\n", ifn );
exit( 1 );
}
/* compute the minimum and maximum price in the input file */
max = 0.0;
min = 9999999.0;
while( fscanf( ifp, "%f", &flt ) == 1 ) {
if ( flt < min ) min = flt;
if ( flt > max ) max = flt;
}
/* compute scaling so that new prices vary from 0.1 to 0.9 */
scale = 0.8 / (max - min);
offset = 0.1 - scale * min;
/* tell the user what scale and offset we are using */
fprintf( stderr, "scale = %.4f, offset = %.4f\n", scale, offset );
/* re-parse the input file and convert prices */
fseek( ifp, 0l, 0 );
while( fscanf( ifp, "%f", &flt ) == 1 ) {
fprintf( ofp, "%.3f\n", flt*scale + offset );
}
/* close the input and output files */
fclose( ifp );
fclose( ofp );
}